package com.china08.yxyapi.api.manage.tec.teaching.resource.myresource;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.service.yxyresource.YxyResourceService;
import com.china08.yxyapi.util.EsResourceUpdateUtil;

import io.swagger.annotations.ApiOperation;

/**
 * 老师 我的资源 删除
 * 
 */
@CrossOrigin
@RestController
public class MyResourceDelController extends YxyApiBaseController {

    @Autowired
    private YxyResourceService yrs;

    @ApiOperation(value = "老师删除我的资源")
    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/tec/teaching/resource/myresource/del", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String userId = getProfile(request, response).getId();
        RespModel model = new RespModel();
        yrs.delRes(reqModel.ids, userId);
        for (String resId : reqModel.ids) {
            EsResourceUpdateUtil.updateEsResoure(resId);
        }
        model.setMessage("成功");
        return model;
    }

    public static class ReqModel extends YxyApiReqModel {
        public String[] ids;

        @Override
        public void autoCheck() {
            Assert.isTrue(ids != null && ids.length > 0 ? true : false, "请指定要删除的资源");
        }

    }

    public static class RespModel extends YxyApiRespModel {

    }

}